function setTableWhere(){
        var url = "./index.php?type=table&action=setTableWhere";
        var post = new Object();
        $(":input.search").each(function(){
            var i = getFieldId(this.id);
            if(this.type == "checkbox"){
               if(this.checked == true) post[i] = 1;
               else post[i] = 0;
            }
            else{
                post[i] = this.value;
            }
        });
        $("tbody#target").load(url,post,function(){
            var url = './index.php?type=table&action=getPagesCount';
            $('div.paging').load(url);
        });
}

function setTableOrder(fieldId){
    var url = "./index.php?type=table&action=setTableOrder";
    var post = new Object();
    $("table.main div.columnName").removeClass("marked");
    $('#'+fieldId).addClass("marked");
    post['fieldId'] = getFieldId(fieldId);
    $("tbody#target").load(url,post);
}

function setTableLimit(page){
    var url = "./index.php?type=table&action=setLimit";
    var post = new Object();
    post["page"] = page;
    $("tbody#target").load(url,post,function(){
        var url = './index.php?type=table&action=getPagesCount';
        $('div.paging').load(url);
    });
}

function setTableRowsPerPage(rowsPerPage){
    var url = "./index.php?type=table&action=setRowsPerPage";
    var post = new Object();
    post["rowsPerPage"] = rowsPerPage;
     $("tbody#target").load(url,post,function(){
        var url = './index.php?type=table&action=getPagesCount';
        $('div.paging').load(url);
    });
}

function tableOnLoad(){
    $(document).ready(function() {
       createDaD();
    });
    $('.tabs').tabs();
}

function createDaD(){
    var onDragValues = new Array;
    var onDropValues = new Array;
    $("table.main#subject tbody, table.main#field tbody").tableDnD();
    $("table.main#subject tbody, table.main#field tbody").tableDnD({
        onDragClass: "rowDrag",
        onDragStart: function(table, row){
            $("table.main tbody tr").removeClass('row');
             $("table.main tbody tr td").css("opacity","0.6");
             $("table.main tbody tr#row-"+row.id+" td").css("opacity","1");
            var onDragRows = table.rows;
            for (var i=0; i<onDragRows.length; i++) {
                onDragValues[i] = getFieldId(onDragRows[i].id);
            }
        },
        onDrop: function(table) {
             $("table.main tbody tr td").css("opacity","1");
            $("table.main tbody tr").addClass('row');
            var onDropRows = table.rows;
            for (var i=0; i<onDropRows.length; i++) {
                onDropValues[i] = getFieldId(onDropRows[i].id);
            }
            if($(onDragValues).compare(onDropValues) === false){
                var post = new Object;
                post["sequence"] = new Object;
                post["sequence"] = onDropValues;
                var url ="./table.php?action=setTableSequence";
                $.post(url,post);
            }
        }
    });
}

function dbClickEdit(){
    $("table.main tbody tr").dblclick(function(){
        var itemId = getFieldId(this.id);
        window.location ="index.php?type=form&action=open&id="+itemId;
    });
}

function multiDelete(){
    var url = "./index.php?type=form&action=multiDelete";
    var post = new Object;
    post["id"] = new Object;
    var i = 0;
    $("input.multiEdit:checked").each(function(){
        post["id"][i++] = this.id;
    });
    if(i == 0) alert("Nie wybrano \u017cadnego wpisu");
    else
    if (confirm("Zaznaczono wpisów: "+i+"\nCzy napewno usunąć je?" )){
         $.post(url,post,function(){
            window.location ="index.php?type=form&action=close";
        });
    }
}